var e = getApp(), t = require("../../../component/WxNotificationCenter/WxNotificationCenter.js");

Page({
    data: {
        schedule: [],
        reservedays: [],
        hideControl: !1
    },
    onLoad: function(e) {
        "1" == e.hideControl && this.setData({
            hideControl: !0
        });
        var t = e.schedule, i = JSON.parse(t);
        this.setData({
            schedule: i
        }), 2 == i.type && this.setUpReserveDate();
    },
    setUpReserveDate: function() {
        for (var e = [], t = 1; t <= 365; t++) e = e.concat(t + "天");
        this.setData({
            reservedays: e
        });
    },
    changeReserveDay: function(e) {
        if (1 != this.data.hideControl) {
            var t = parseInt(e.detail.value) + 1;
            this.editReservedDay(t);
        }
    },
    clickConfirm: function(e) {
        var t = this;
        wx.showModal({
            title: "提示",
            content: "确定订单？",
            success: function(e) {
                e.confirm && t.confirmSchedule();
            }
        });
    },
    blindCallClick: function(e) {
        var t = e.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber: t
        });
    },
    clickPirceEnd: function(e) {
        if (1 != this.data.hideControl && 1 != this.data.schedule.priceState) {
            var t = this;
            wx.showModal({
                title: "提示",
                content: "确定已结清？",
                success: function(e) {
                    e.confirm && t.doPayEnd();
                }
            });
        }
    },
    bindEditClick: function(e) {
        var t = JSON.stringify(this.data.schedule);
        console.log(t), wx.navigateTo({
            url: "/pages/schedule/addSchedule/addSchedule?isEdit=true&schedule=" + t
        });
    },
    bindDelClick: function(e) {
        var t = this;
        wx.showModal({
            title: "提示",
            content: "确定要删除档期？",
            success: function(e) {
                e.confirm && t.doDelect();
            }
        });
    },
    bindImageTap: function(e) {
        var t = this.data.schedule.images.split(",");
        wx.previewImage({
            current: e.currentTarget.dataset.url,
            urls: t
        });
    },
    editReservedDay: function(i) {
        var a = this;
        e.network.post({
            url: e.url.editScheduleEeservedTime,
            params: {
                id: a.data.schedule.scheduleId,
                reservedTime: i
            },
            before: function() {
                wx.showLoading({
                    title: "正在修改"
                });
            },
            success: function(o) {
                if (wx.hideLoading(), 1 == o.data.result) {
                    var n = a.data.schedule;
                    n.reservedTime = i, a.setData({
                        schedule: n
                    }), t.postNotificationName("updateScheduleList");
                } else e.util.showToast(o.data.message);
            },
            fail: function() {
                wx.hideLoading(), e.util.showToast("修改失败");
            },
            complete: function() {}
        });
    },
    doDelect: function() {
        var i = this;
        e.network.post({
            url: e.url.deleteSchedule,
            params: {
                id: i.data.schedule.scheduleId
            },
            before: function() {
                wx.showLoading({
                    title: "正在删除"
                });
            },
            success: function(i) {
                wx.hideLoading(), 1 == i.data.result ? (t.postNotificationName("updateScheduleList"), 
                wx.navigateBack({})) : e.util.showToast(i.data.message);
            },
            fail: function() {
                wx.hideLoading(), e.util.showToast("获取数据失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading();
            }
        });
    },
    doPayEnd: function() {
        var i = this;
        e.network.post({
            url: e.url.setSchedulePriceState,
            params: {
                id: i.data.schedule.scheduleId
            },
            before: function() {
                wx.showLoading({
                    title: "正在提交"
                });
            },
            success: function(a) {
                if (wx.hideLoading(), 1 == a.data.result) {
                    var o = i.data.schedule;
                    o.priceState = 1, i.setData({
                        schedule: o
                    }), t.postNotificationName("updateScheduleList");
                } else e.util.showToast(a.data.message);
            },
            fail: function() {
                wx.hideLoading(), e.util.showToast("获取数据失败");
            },
            complete: function() {}
        });
    },
    confirmSchedule: function() {
        var i = this;
        e.network.post({
            url: e.url.confirmSchedule,
            params: {
                id: i.data.schedule.scheduleId
            },
            before: function() {
                wx.showLoading({
                    title: "正在确定"
                });
            },
            success: function(a) {
                if (wx.hideLoading(), 1 == a.data.result) {
                    var o = i.data.schedule;
                    o.type = 1, i.setData({
                        schedule: o
                    }), t.postNotificationName("updateScheduleList");
                } else e.util.showToast(a.data.message);
            },
            fail: function() {
                wx.hideLoading(), e.util.showToast("确定失败");
            },
            complete: function() {}
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});